package com.wgchao.authmanager.infrastructure.resp;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;

/**
 * @作者：wgchao
 * @时间：10:06 2020/5/5 0005
 * @用途：返回值
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "backResult", description = "统一返回数据")
public class BackResult<T> implements Serializable {

    @ApiModelProperty(value = "结果编号（200成功）", name = "code", required = true)
    private String code;

    @ApiModelProperty(value = "返回结果描述", name = "message", required = true)
    private String message;

    @ApiModelProperty(value = "返回数据", name = "data", required = false, allowEmptyValue = true)
    private T data;

    public static BackResult success(){
        BackResult backResult = new BackResult();
        backResult.code = "200";
        backResult.message = "成功";
        return backResult;
    }

    public static BackResult fail(){
        BackResult backResult = new BackResult();
        backResult.code = "999";
        backResult.message = "失败";
        return backResult;
    }

    public static BackResult fail(String message){
        BackResult backResult = new BackResult();
        backResult.code = "999";
        backResult.message = message;
        return backResult;
    }

    public static BackResult fail(String code, String message){
        BackResult backResult = new BackResult();
        backResult.code = code;
        backResult.message = message;
        return backResult;
    }

    public BackResult setMsg(String message){
        this.message = message;
        return this;
    }

    public BackResult setData(T data){
        this.data = data;
        return this;
    }
}
